package com.example.demo.mapper;

import com.example.demo.entity.LikeNoteComment;
import org.apache.ibatis.annotations.*;

@Mapper
public interface LikeNoteCommentMapper {

    //实现点赞
    @Insert("insert into like_notecomment_tb (user_id,note_comment_id) values (#{user_id},#{note_comment_id})")
    int insertLikeNoteComment(LikeNoteComment likeNoteComment);


    //取消点赞
    @Delete("delete from like_notecomment_tb where user_id=#{user_id} and note_comment_id = #{note_comment_id}")
    int deleteLikeNoteComment(@Param("user_id") Integer user_id, @Param("note_comment_id") Integer note_comment_id);


    //检查用户是否已经点赞过某条评论
    @Select("SELECT COUNT(*) FROM like_notecomment_tb WHERE user_id = #{user_id} AND note_comment_id = #{note_comment_id}")
    int checkIfLike(@Param("user_id") Integer user_id, @Param("note_comment_id") Integer note_comment_id);

    //根据评论id统计对应评论点赞数量
    @Select("select COUNT(*) FROM like_notecomment_tb WHERE note_comment_id = #{note_comment_id}")
    Integer countLike(@Param("note_comment_id") Integer note_comment_id);

}
